package com.file.controller;

import com.common.enums.error.ResultEnum;
import com.common.result.Result;
import com.common.util.StringUtil;
import com.file.service.FileService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: stefanie-zy
 * @time: 2024/1/29-11:11
 * @description: 文件控制层
 */
@Tag(name = "文件接口")
@ApiSort(1)
@RequestMapping(value = "/api-file")
@RequiredArgsConstructor
@RestController
@Slf4j
@ApiSupport(author = "stefanie-zy", order = 1)
public class FileController {

    private final FileService fileService;

    @GetMapping(value = "/user-ico")
    @Operation(summary = "生成用户默认头像")
    public Result<?> getUserIcoUrl(String userName) {
        String userIcoPath = fileService.createUserIco(userName);
        if (StringUtil.isNotEmpty(userIcoPath)) {
            return Result.success(userIcoPath);
        }
        return Result.fail(ResultEnum.B_ICO_CREATE_ERROR);
    }

}
